<?php	
	session_start();
	include 'include/db.php';
		$username = $_POST['username'];
		$password = $_POST['password'];
		$email = $_POST['email'];
		$first_name = $_POST['first_name'];
		$last_name = $_POST['last_name'];
		$country = $_POST['country'];
					
		if (mysql_num_rows(mysql_query("SELECT id FROM users WHERE username='$username'")) > 0) { 
			die ("Username already exists <a href='register.php'>Back</a>"); 
		} else {
			$x = rand(0,300);
			$y = rand(0,300);
			mysql_query("INSERT INTO users (username, password, email, first_name, last_name, 	country, cash) VALUES ('$username','$password','$email','$first_name','$last_name','$country', 0)") or die ("Could not register player. Please try again later. <a href='register.php'>Back</a>");
			$ownerid = mysql_result(mysql_query("SELECT id FROM users WHERE username=$username"),0);
			mysql_query("INSERT INTO hospitals (owner_id,x,y) VALUES ('$ownerid',$x,$y)") or die ("Could not register player. Please try again later. <a href='register.php'>Back</a>");
			$_SESSION['username'] = $username;
			echo "Registration successful. <a href='index.php'>Back to Home</a>";
		}
?>